import 'package:financing_wallet/mine/contentType.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/location/locationUtil.dart';
import 'package:wallet_utils/login_utils.dart';
import 'package:wallet_utils/report_widget/base/callback/base_callback.dart';
import 'package:wallet_utils/toast.dart';

import '../api/mine_api.dart';
import '../bean/aboutUsBean.dart';
import 'state.dart';

class SettingLogic extends GetxController {
  final SettingState state = SettingState();

  @override
  void onInit() {
    super.onInit();
  }

  void mineCheck(int index) {
    switch (index) {
      case 0:
        getUserInfo(ContentType.newPrivacyPolicy);
        break;
      case 1:
        getUserInfo(ContentType.registration);
        break;
    }
  }

  ///关于我们
  getUserInfo(int type) {
    MineApi.getHTML(
        type,
        BaseCallback(onSuccess: (map) {
          AboutUsBean aboutUsBean = AboutUsBean.fromJson(map);
          if (aboutUsBean.data != null) {
            String? name = aboutUsBean.data?.name;
            String? content = aboutUsBean.data?.content;
            Get.toNamed(BaseRouterConfig.agreement, arguments: {'name': name, 'content': content});
          }
        }, onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            ToastUtils.showToast(msg ?? "");
          });
        }));
  }

  cancellation() {
    MineApi.cancellation(BaseCallback(
        onSuccess: (map) {
          logOut();
        },
        onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            ToastUtils.showToast(msg ?? "");
          });
        }));
  }

  void logOut(){
    LoginUtils.loginOut();
    LocationUtil().stopLocation();
    LocationUtil().cancel();
    LocationUtil().destroyLocation();
    Get.offAllNamed(BaseRouterConfig.smsPage,arguments: {'isFirst': true}); //跳转登录页面
  }
}
